package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;

@Controller
@RequestMapping(value = "/student")
public class UpdateStudentPwdController extends BaseController {

	@Autowired
	private BizService bizService;

	@Autowired
	private BizDao bizDao;

	private static Logger logger = LoggerFactory.getLogger(BaseController.class);
	/**
	 * 修改学员密码
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/updateStudentPwd", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String updateStudentPwd(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");
		try { 
			// 学员电话
			String mobilePhone = request.getParameter("mobilePhone");
			// 旧密码
			String oldPwd = request.getParameter("oldPwd");
			// 新密码
			String newsPwd = request.getParameter("newsPwd");
			if((null != mobilePhone && !mobilePhone.equals(""))
					&& (null != oldPwd && !oldPwd.equals(""))
					&& (null != newsPwd && !newsPwd.equals(""))){
				//修改密码
				response = bizService.updatePassword(mobilePhone,oldPwd,newsPwd,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填字段！");
			}
		} catch (Exception e) {
			logger.info("UpdatePwdController:"+ e.toString());
		    response.setErrorcode(1);
			response.setMessage("密码修改失败！");
		} finally {
			return response.toJSON();
		}

	}

}
